/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/13 14:24
  *
  * @file       pd_timer_pwm.h
  * @brief      Header file of TimerPWM peripheral driver.
  *
  * @note       This file contains the TimerPWM object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/13     Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_TIMER_PWM_H
#define JLC_SKY_TIMER_PWM_H

#include "pd_gpio.h"
#include "pd_timer.h"
#include "pd_timer_oc.h"

struct TimerPWMVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    Timer *timer;
    TimerOC *timerOC;

    // TimerPWM virtual table
    struct TimerPWMVtbl *vptr;
} TimerPWM;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct TimerPWMVtbl {
    void (*init)(const TimerPWM *this);

    void (*set_pwm_duty)(const TimerPWM *this, const uint32_t channel, const uint32_t val);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void TimerPWM_constructor(TimerPWM *this, Timer *timer, TimerOC *timerOC);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void TimerPWM_init(const TimerPWM *this) {
    this->vptr->init(this);
}

static inline void TimerPWM_setDuty(const TimerPWM *this, const uint32_t channel, const uint32_t val) {
    this->vptr->set_pwm_duty(this, channel, val);
}
/**
 * @}
 */


#endif //JLC_SKY_TIMER_PWM_H
